<?php
/**
 * [商网通 System] Copyright swtshop.cn
 * QQ: 1170787711
 * Author: gj.name
 * This is NOT a freeware
*/
class wap extends module
{
    function __construct()
    {
        $this->uid = @$_SESSION['user']['uid'];
        $this->wchat_uid = @$_SESSION['connect']['wchat']['openid'];
        parent::__construct();
    }
    function index()
    {
        $site_status = cfg('site_status');
        if ($site_status == '4') {
            error_404('站点临时关闭');
        }
        $m = isset($_GET['m']) ? $_GET['m'] : 'index';
        $a = isset($_GET['a']) ? $_GET['a'] : 'index';
        if (cfg('browser') == 'wchat') {
            if (empty($this->wchat_uid)) {
                $code = isset($_GET['code']) ? $_GET['code'] : '';
                if (isset($_GET['code'])) {
                    $wchat_uid = wchat::init()->openid($code);
                    @($_SESSION['connect']['wchat']['openid'] = $wchat_uid);
                    $urow = $this->db->get_one("select * from " . table('member') . " where wchat_uid = '" . $wchat_uid . "'");
                    if ($urow['uid']) {
                        $this->module('user')->user_session($urow);
                    }
                } else {
                    wchat::init()->get_code();
                }
            }
        }
        if ($m == 'index' && $a == 'index') {
        } else {
            if ($m == 'cart' && $a == 'settle' || $m == 'member' && $a == 'index' || $m == 'order' || $m == 'address' || $m == 'account' || $m == 'collect' || $m == 'refund' || $m == 'album' || $m == 'user') {
                if (empty($_SESSION['user']['uid'])) {
                    if (cfg('browser') == 'wchat') {
                        header("Location:wap.php?m=member&a=login_conn&alias=wchat");
                    } else {
                        header("Location:wap.php?m=member&a=login");
                    }
                }
            }
        }
    }
}